<?php

namespace app\admin\controller;


use utils\Upload;

class UploadController extends AdminBase
{
    public function upfile()
    {
        header("Content-Type: text/html;charset=utf-8");
        $isThumb = input('isThumb');
        $files = Upload::getFiles();
        $result = [];
        foreach ($files as $file) {
            if(!empty($isThumb)){
                $image = \think\Image::open($file->getPathname());
                $image->thumb(150, 150)->save($file->getPathname());
            }

            $result[] = str_replace(ROOT, '', $file->getPathname());
        }

        return $this->okJson('上传成功', $result);
    }

    public function upVideo()
    {
        $video = Upload::getVideo();
        if($video) {
            return $this->okJson('上传成功', $video);
        }else{
            return $this->errJson('上传中', $video);
        }
    }

    public function del()
    {
        $path = input('path');
        if(empty($path)) return $this->errJson('路径不能为空');
        $res = Upload::unlink($path);
        return $this->okJson($res);
    }
}